<?
require_once("../config/dbconn.php");require_once("../config/usercls.php");

$sqlhy="select * from {$db_prefix}users where id='".$_SESSION['sys_userid']."'";
$rshy=$db->get_one($sqlhy);

if ($action=='clear'){
	setcookie('sys_reggoodscart','');
	
	echo "<script>location.href='reg_cart.php';</script>";exit();
}

if ($action=='del'){
	setcookie('sys_reggoodscart','');
	
	echo "<script>location.href='reg_cart.php';</script>";exit();
}

if ($action=='update'){
	$goodcartstr=$_COOKIE['sys_reggoodscart'];
	if ($goodcartstr){
		$goodcartary=explode('|',$goodcartstr);
		foreach($goodcartary as $k1=>$v1){
			$goodcartary1=explode(',',$v1);
			editreggoodscart($goodcartary1[0],$_POST["num_{$goodcartary1[0]}"]);
		}
	}
	echo "<script>location.href='reg_cart.php';</script>";exit();
}


?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
	
}
td{
	font-size:12px;
}
.red{
	font-size:12px; color:#FF0000;
}
-->
</style>
<script language="javascript">
function updatecart(){
	var frm=document.form1;
	frm.submit();
}
</script>
<link href="images/skin.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="17" height="29" valign="top" background="images/mail_leftbg.gif"><img src="images/left-top-right.gif" width="17" height="29" /></td>
    <td width="935" height="29" valign="top" background="images/content-bg.gif"><table width="100%" height="31" border="0" cellpadding="0" cellspacing="0" class="left_topbg" id="table2">
      <tr>
        <td height="31"><div class="titlebt">注册购物车</div></td>
      </tr>
    </table></td>
    <td width="16" valign="top" background="images/mail_rightbg.gif"><img src="images/nav-right-bg.gif" width="16" height="29" /></td>
  </tr>
  <tr>
    <td height="71" valign="middle" background="images/mail_leftbg.gif">&nbsp;</td>
    <td valign="top" bgcolor="#F7F8F9"><table width="100%" height="138" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td height="13" valign="top">&nbsp;</td>
      </tr>
      <tr>
        <td valign="top">
		<form name="form1" id="form1" method="post" action="?action=update">
		<table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td colspan="2"><table width="100%" height="31" border="0" cellpadding="0" cellspacing="0" class="nowtable">
                <tr>
                  <td class="left_bt2">&nbsp;&nbsp;&nbsp;&nbsp;商品列表</td>
                </tr>
              </table></td>
            </tr>
            <tr>
              <td height="30" colspan="2">
                <table width="100%" height="60" border="0" cellpadding="0" cellspacing="1" bgcolor="silver">
                  <tr>
                    <td align="center" bgcolor="#f2f2f2" class="left_txt">商品名称</td>
                    <td align="center" bgcolor="#f2f2f2" class="left_txt">市场价</td>
                    <td align="center" bgcolor="#f2f2f2" class="left_txt">会员价</td>
                    <td align="center" bgcolor="#f2f2f2" class="left_txt">pv</td>
                    <td align="center" bgcolor="#f2f2f2" class="left_txt">购买数量</td>
                    <td align="center" bgcolor="#f2f2f2" class="left_txt">小计</td>
                    <td height="30" align="center" bgcolor="#f2f2f2" class="left_txt">操作</td>
                  </tr>
                  <tbody bgcolor="#FFFFFF">
				<?
				$allprice=0;$allscprice=0;
				$goodcartstr=$_COOKIE['sys_reggoodscart'];
				if ($goodcartstr){
					$goodcartary=explode('|',$goodcartstr);
					foreach($goodcartary as $k1=>$v1){
						$goodcartary1=explode(',',$v1);
						$sqlp="select * from {$db_prefix}products where id='".$goodcartary1[0]."'";
						$rsp=$db->get_one($sqlp);
				?>
                    <tr>
                      <td align="center" class="left_txt"><a href="../uploads/productimgs/<?=$rsp['pimg']?>" target="_blank"><img src="../uploads/productimgs/<?=$rsp['pimg']?>" border="0" width="100"></a><br>
                          <a href="product_view.php?id=<?=$rsp['id']?>">
                            <?=$rsp['productname']?>
                          </a></td>
                      <td align="center" class="left_txt"><?=$rsp['scprice']?>
                        美金</td>
                      <td align="center" class="left_txt"><?=$rsp['price']?>
                        美金</td>
                      <td align="center" class="left_txt"><?=$rsp['pv']?>
                        pv</td>
                      <td align="center" class="left_txt"><label>
                        <input name="num_<?=$rsp['id']?>" type="text" id="num_<?=$rsp['id']?>" size="5" value="<?=$goodcartary1[1]?>">
                      </label></td>
                      <td align="center" class="left_txt"><? 
					  $allprice+=$rsp['price']*$goodcartary1[1];
					  $allscprice+=$rsp['scprice']*$goodcartary1[1];
					  echo ($rsp['price']*$goodcartary1[1]);
					  ?>
                        美金</td>
                      <td height="30" align="center" class="left_txt"><A href="?action=del&pid=<?=$rsp['id']?>"><img src="images/pic22.gif" width="17" height="15" border="0">删除</A></td>
                    </tr>
                    <?
					}
				}else{
				?>
                    <tr>
                      <td align="center" class="left_txt">&nbsp;</td>
                      <td align="center" class="left_txt">&nbsp;</td>
                      <td align="center" class="left_txt">&nbsp;</td>
                      <td align="center" class="left_txt">&nbsp;</td>
                      <td align="center" class="left_txt">&nbsp;</td>
                      <td align="center" class="left_txt">&nbsp;</td>
                      <td height="30" align="center" class="left_txt"><A href=""></A></td>
                    </tr>
                    <?
				}
				?>
                  </tbody>
                </table>
				</td>
            </tr>
            <tr style="display:none">
              <td height="30" align="right">订单类型：
                <label></label></td>
              <td height="30" align="left"><select name="type" id="type">
                <option value="0">注册订单</option>
              </select></td>
            </tr>
            <tr>
              <td height="30" align="left" class="red">购物金额小计 ￥<?=$allprice?>美金，比市场价 ￥<?=$allscprice?>美金 节省了 ￥<?=($allscprice-$allprice)?>美金  </td>
              <td width="44%" height="30" align="right"><a href="?action=clear"><img src="images/gw.gif" width="16" height="16" border="">清空注册购物车</a>
                <a href="javascript:updatecart();"><img src="images/gw2.gif" width="16" height="16" border="0">更新注册购物车</a></td>
            </tr>
            <tr>
              <td height="30">&nbsp;</td>
              <td height="30" align="right">&nbsp;</td>
            </tr>
            <tr>
              <td height="30"><a href="product_buy.php"><img src="images/continue.gif" width="125" height="40" border="0"></a></td>
              <td height="30" align="right"><a href="user_reg.php"><img src="images/Login_but.gif" border="0"></a></td>
            </tr>
          </table>
		 </form>
		  </td>
      </tr>
    </table></td>
    <td background="images/mail_rightbg.gif">&nbsp;</td>
  </tr>
  <tr>
    <td valign="middle" background="images/mail_leftbg.gif"><img src="images/buttom_left2.gif" width="17" height="17" /></td>
      <td height="17" valign="top" background="images/buttom_bgs.gif"><img src="images/buttom_bgs.gif" width="17" height="17" /></td>
    <td background="images/mail_rightbg.gif"><img src="images/buttom_right2.gif" width="16" height="17" /></td>
  </tr>
</table>

</body>
</html>